
import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  Image,
  TouchableOpacity,
  Switch,
} from 'react-native';
export default class CommonCell extends Component {
  constructor(props){
    super(props);
    this.state={
      isOn:false,
    };
  }
  /*
  getDefaultProps(){
    return{
      title:'',
    }
  }
  */
  renderRightView(){
    if(this.props.isSwitch){
      return (
        <Switch value={this.state.isOn == true} onValueChange={()=>{this.setState({isOn:!this.state.isOn})}} style={{marginRight:8}}/>
      );
    } else {
      return (
        <View style={{flexDirection:'row',alignItems:'center'}}>
          {this.rightTitle()}
          <Image source={{uri:'icon_cell_rightarrow'}} style={{width:8,height:13,marginRight:10}}/>
        </View>
      );
    }
  }
  rightTitle(){
    if(this.props.rightTitle){
      return(
        <Text style={{color:'gray',marginRight:3}}>{this.props.rightTitle}</Text>
      );
    }
  }
  render() {
    return (
      <TouchableOpacity>
        <View style={styles.container}>
          <Text style={{marginLeft:10}}>{this.props.title}</Text>
          {this.renderRightView()}
        </View>
      </TouchableOpacity>
    );
  }
}

const styles = StyleSheet.create({
  container:{
    height:Platform.OS==='ios'?40:40,
    backgroundColor:'white',
    borderBottomColor:"#ddd",
    borderBottomWidth:0.5,
    flexDirection:'row',
    justifyContent:'space-between',
    alignItems:'center',
  },
});
